#ifndef __MEM_MALLOC_H__
#define __MEM_MALLOC_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h> 
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

//内存堆-对象
typedef struct mem_heap
{
	unsigned int sum;	/*用于记录已使用的长度*/
	unsigned int size;	/*内存堆的长度*/ 
	unsigned char* mem;	/*内存堆的首地址*/
}mem_heap;

void print_heap_info(const mem_heap* heap);
void print_heap_hex(const mem_heap* heap);
int heap_malloc(mem_heap* heap,unsigned int msize);
int heap_realloc(mem_heap* heap,int id, unsigned int msize);
void *heap_buffer(const mem_heap* heap,int id);
int heap_free(mem_heap* heap,int id);

/**-----------------------------------**/
#define MEM_SIZE        128
static char			mem[MEM_SIZE];
static mem_heap MEM={.sum=0,.size=MEM_SIZE,.mem=mem};

#define print_mem_info()  print_heap_info(&MEM)
#define print_mem_hex()   print_heap_hex(&MEM)  
#define mem_malloc(msize)  heap_malloc(&MEM,msize)
#define mem_realloc(id,msize) heap_realloc(&MEM,id,msize)
#define mem_buffer(id)      heap_buffer(&MEM,id)
#define mem_free(id)        heap_free(&MEM,id)


#ifdef __cplusplus
}
#endif

#endif
